/**
 * @Created Nov 4, 2011 2:20:34 PM
 * @author cry30
 */
package com.philip.util;

/**
 * Collected methods which allow easy implementation of <code>equals</code>.
 *
 * Example use case in a class called Car:
 *
 * <pre>
 * public boolean equals(Object aThat) {
 *     if (this == aThat)
 *         return true;
 *     if (!(aThat instanceof Car))
 *         return false;
 *     Car that = (Car) aThat;
 *     return EqualsUtil.areEqual(this.fName, that.fName) &amp;&amp; EqualsUtil.areEqual(this.fNumDoors, that.fNumDoors)
 *             &amp;&amp; EqualsUtil.areEqual(this.fGasMileage, that.fGasMileage) &amp;&amp; EqualsUtil.areEqual(this.fColor, that.fColor)
 *             &amp;&amp; Arrays.equals(this.fMaintenanceChecks, that.fMaintenanceChecks); //array!
 * }
 * </pre>
 *
 * <em>Arrays are not handled by this class</em>. This is because the <code>Arrays.equals</code> methods
 * should be used for array fields.
 */
public final class EqualsUtil {

    /** Utility class. */
    private EqualsUtil() {}

    /**
     * @param aThis - RTFC.
     * @param aThat - RTFC.
     * @return true if equal, duh!
     */
    public static boolean areEqual(final boolean aThis, final boolean aThat) {
        return aThis == aThat;
    }

    /**
     * @param aThis - RTFC.
     * @param aThat - RTFC.
     * @return true if equal, duh!
     */
    public static boolean areEqual(final char aThis, final char aThat) {
        return aThis == aThat;
    }

    /**
     * Implementation Note Note that byte, short, and int are handled by this method, through implicit
     * conversion.
     *
     * @param aThis - RTFC.
     * @param aThat - RTFC.
     * @return true if equal, duh!
     */
    public static boolean areEqual(final long aThis, final long aThat) {
        return aThis == aThat;
    }

    /**
     * @param aThis - RTFC.
     * @param aThat - RTFC.
     * @return true if equal, duh!
     */
    public static boolean areEqual(final float aThis, final float aThat) {
        return Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat);
    }

    /**
     * @param aThis - RTFC.
     * @param aThat - RTFC.
     * @return true if equal, duh!
     */
    public static boolean areEqual(final double aThis, final double aThat) {
        return Double.doubleToLongBits(aThis) == Double.doubleToLongBits(aThat);
    }

    /**
     * Possibly-null object field.
     *
     * Includes type-safe enumerations and collections, but does not include arrays. See class comment.
     *
     * @param aThis - RTFC.
     * @param aThat - RTFC.
     * @return true if equal, duh!
     */
    public static boolean areEqual(final Object aThis, final Object aThat) {
        return aThis == null ? aThat == null : aThis.equals(aThat);
    }
}